﻿// ===============================================================================
// DotNet.Platform 开发框架 2016 版权所有
// ===============================================================================

using System;
using System.Web.Mvc;
using System.Web.Security;

namespace DotNet.Web
{
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false)]
    public sealed class DomainLogInAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var key = "_dotnet_user_";
            if (filterContext.HttpContext.Session != null 
                && filterContext.HttpContext.Session[key] == null)
            {
                filterContext.Result = new RedirectResult(FormsAuthentication.LoginUrl);
            }
        }
    }
}